package com.hnkywl.sts.service.kcgl;

import com.hnkywl.sts.dao.organ.NbgsDao;
import com.hnkywl.sts.entity.organ.Nbgs;
import com.hnkywl.sts.util.BaseUtils;
import net.ruixin.orm.hibernate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-6-16
 * Time: 下午5:14
 * To change this template use File | Settings | File Templates.
 */
@Service
public class RkpzService {
    private NbgsDao nbgsDao;

    @Transactional
    public String findAllNbgs(String name, int pageNo, int pageSize) {
        Page<Nbgs> gsjgPage = this.nbgsDao.findAllNbgs(name, pageNo, pageSize);
        List<Nbgs> gsjgList = gsjgPage.getResult() == null ? new ArrayList<Nbgs>() : gsjgPage.getResult();
        String gsjgJson = BaseUtils.fetchCollectionToJson(gsjgList, "id", "jc", "sfqydhdrk");
        return "{\"total\":" + gsjgPage.getTotalCount() + ",\"rows\":[" + gsjgJson + "]}";
    }

    @Transactional
    public Nbgs findrkpzDetail(Long id) {
        return this.nbgsDao.get(id);
    }

    @Transactional
    public void changeStatus(Long id, Boolean status) {
        Nbgs rkpz = this.findrkpzDetail(id);
        rkpz.setSfqydhdrk(status);
        this.nbgsDao.save(rkpz);
    }

    @Autowired
    public void setNbgsDao(NbgsDao nbgsDao) {
        this.nbgsDao = nbgsDao;
    }
}
